package com.wendu.oa.service.security.impl;

import com.wendu.oa.common.page.PageUtils;
import com.wendu.oa.dao.security.UserDao;
import com.wendu.oa.dto.MenuDto;
import com.wendu.oa.dto.UserDto;
import com.wendu.oa.model.Role;
import com.wendu.oa.service.security.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    public Map<String, Object> getUserPage(UserDto userDto) {
        return PageUtils.getPage(userDto,()-> userDao.findUserList(userDto));
    }

    @Override
    public void setRoles(String u_id, Integer[] ro_ids) {

        userDao.deleteUserAllRoles(u_id);

        if(ro_ids == null || ro_ids.length == 0)return;

        userDao.insertUserRoles(u_id,ro_ids);
    }

    @Override
    public List<Role> getRoleList() {

        return userDao.findRoleList();

    }

    @Override
    public Integer[] getUserRoleIds(String u_id) {
        return userDao.findUserRoleIds(u_id);
    }
}
